package day03.`match`

/**
  * PartialFunction[A,B],其中A是参数类型，B是返回值类型，
  * PartialFunction(偏函数) 常用于模式匹配
  */
object PartialFuncationDemo {
  def m1:PartialFunction[String,Int]={
    case "one" =>{
      println("case one")
      1
    }
    case "two" =>{
      println("case two")
      2
    }
    case _ =>{
      println("case zero")
      0
    }
  }

  def m2(param:String):Int=param match {
    case "one" =>{
      println("case one")
      1
    }
    case "two" =>{
      println("case two")
      2
    }
    case _ =>{
      println("case zero")
      0
    }
  }

  def main(args: Array[String]): Unit = {
    println(m1("one1"))
    println("-------------------------------")
    println(m1("two"))
  }
}
